﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KMF.Common;

namespace KMF.DAL
{
    public partial class ProductTogetherDb
    {
        public static int AddProductTogether(string ProductId,string MapId,bool show)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductTogether_AddNew");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@productId", ProductId));
                command.Parameters.Add(dao.CreateParameter("@MappingId", MapId));
                command.Parameters.Add(dao.CreateParameter("@Show", show));
                var result = command.ExecuteNonQuery();
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }

        public static int DelAllTogether(string ProductId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductTogether_DelByProductId");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@ProductId", ProductId));
                var result = command.ExecuteNonQuery();
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }
        public static List<ProductByCateTopListPagingDto> GetProductTogetherByProductId(string productId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductTogether_GetByProductId");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@ProductId", productId));
                var result = dao.GetDTOList<ProductByCateTopListPagingDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }
    }
}
